package javabase.schoolwork.day6_5;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author fance
 * @date 2018/6/5 20:35
 */
public class Sum {
    public void math() {
        System.out.println(Math.sqrt(9));
        System.out.println(Math.max(9,10));
        System.out.println(Math.pow(2,3));
        System.out.println(Math.round(9.1));
    }
    public void random() {
        Random random = new Random(47);
        for (int i = 0; i < 10; i++) {
            System.out.println(random.nextInt(100) + "\t");
        }
    }
    public void numberFormat() {
        NumberFormat numberFormat = NumberFormat.getInstance();
        System.out.println(numberFormat.format(1000000000));
        System.out.println(numberFormat.format(1000.345));
    }
    public void decimalFormat(String pattern,double val) {
        DecimalFormat decimalFormat = new DecimalFormat(pattern);
        String s = decimalFormat.format(val);
        System.out.println("p " + pattern + " get " + s);
        }
    public void bigInteger() {
        BigInteger bigInteger1 = new BigInteger("123456789");
        BigInteger bigInteger2 = new BigInteger("987654321");
        System.out.println(bigInteger2.add(bigInteger1));
        System.out.println(bigInteger2.subtract(bigInteger1));
        System.out.println(bigInteger2.multiply(bigInteger1));
        System.out.println(bigInteger2.divide(bigInteger1));
        System.out.println(bigInteger2.max(bigInteger1));
        System.out.println(bigInteger2.min(bigInteger1));
        BigInteger[] res = bigInteger2.divideAndRemainder(bigInteger1);
        System.out.println(res[0] + " " + res[1]);
        }
    public void bigDecimal() {
        BigDecimal bigDecimal1 = new BigDecimal(Double.MAX_VALUE);
        BigDecimal bigDecimal2 = new BigDecimal(Double.MAX_VALUE);
        System.out.println(bigDecimal2.add(bigDecimal1));
        System.out.println(bigDecimal2.subtract(bigDecimal1));
        System.out.println(bigDecimal2.multiply(bigDecimal1));
        System.out.println(bigDecimal2.divide(bigDecimal1));

        }
    public void round(double num,int scale) {
        BigDecimal bigDecimal = new BigDecimal(num);
        System.out.println(bigDecimal.divide(new BigDecimal(1),scale,BigDecimal.ROUND_HALF_UP).doubleValue());
        System.out.println(bigDecimal.divide(new BigDecimal(1),scale,BigDecimal.ROUND_HALF_UP));

        }
    public void arraysSort() {
        int[] tmp = {3,5,7,9,1,2,6,8};
        Arrays.sort(tmp);
        System.out.println(Arrays.toString(tmp));
        System.out.println(Arrays.binarySearch(tmp,3));
        Arrays.fill(tmp,-1);
        System.out.println(Arrays.toString(tmp));
        }

    public boolean isNumberStrI(String s) {
            if (s == null || s.length() < 1) {
                return false;
            }
            for (int i = 0; i < s.length(); i++) {
                char cur = s.charAt(i);
                if (cur > '9' || cur < '0') {
                    return false;
                }
            }
            return true;
        }
    public boolean isNumberStrII(String s) {
            if (s == null || s.length() < 1) {
                return false;
            }
            return s.matches("\\d+");
        }

    private void regexI() {
            String str = "a1b2c3";
            Pattern pattern = Pattern.compile("\\d+");
            String[] s = pattern.split(str);
            for (int i = 0; i < s.length; i++) {
                System.out.println(s[i]);
            }


            String str1 = "hellofdasfas";
            Pattern pattern1 = Pattern.compile("\\w{6,15}");
            Matcher matcher = pattern1.matcher(str1);
            if (matcher.matches()) {
                System.out.println("ok");
            }
    }
    private void regexII(String s) {
        System.out.println(s.matches("\\d{4}-\\d{2}-\\d{2}"));
        // email
        // \\w+@\\w+\\.\\w+
        // ip   \\.
    }


    public void randomII() {
        Random random = new Random(47);
        List<List<Integer>> ball = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            List<Integer> cur = new ArrayList<>();
            cur.add(random.nextInt(17) + 1);
            for (int j = 0; j < 6; j++) {
                cur.add(random.nextInt(34) + 1);
            }
            ball.add(cur);
        }
        for (List<Integer> cur : ball) {
            for (Integer tmp : cur) {
                System.out.print(tmp + " ");
            }
            System.out.println();
        }
    }
    @Test
    public void test() {
       // math();
       // random();
       // numberFormat();
       /* decimalFormat("###,###,###",111222.34567);
        decimalFormat("000,000,000",111222.34567);
        decimalFormat("###,###,###￥",111222.34567);
        decimalFormat("000,000,000￥",111222.34567);
        decimalFormat("##.###%",0.345678);
        decimalFormat("00.###%",0.345678);
        decimalFormat("##.###",0.345678);*/
       // bigInteger();

       // bigDecimal();
       // round(3.4,2);

       // arraysSort();

       /* System.out.println(isNumberStrI("123"));
        System.out.println(isNumberStrI("-123"));
        System.out.println(isNumberStrI("a23"));
        System.out.println(isNumberStrII("123"));
        System.out.println(isNumberStrII("-123"));
        System.out.println(isNumberStrII("a23"));*/

       // regexI();
      //  regexII("1997-01-02");
        randomII();
    }

}
